const merge = require('webpack-merge');
const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// const PrerenderSPAPlugin = require('prerender-spa-plugin');
// const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
var ZipPlugin = require('zip-webpack-plugin');
const base = require('./webpack.base.config.js');
const path = require('path');


module.exports = function(env, argv) {
    return merge(base(env, argv), {
        target: 'web',
        mode: 'production',
        externals: {
            'vue': 'Vue',
            'vue-router': 'VueRouter',
            'axios': 'axios',
            'vuex': 'Vuex',
            'element-ui': 'ELEMENT'
        },
        plugins: [
            // new BundleAnalyzerPlugin(),
            new HtmlWebpackIncludeAssetsPlugin({
                assets: [
                  {
                    path: '//cdnjs.cloudflare.com/ajax/libs/vue/2.6.8/vue.min.js',
                    type: 'js'
                  },
                  {
                    path: '//cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js',
                    type: 'js'
                  },
                  {
                    path: '//cdnjs.cloudflare.com/ajax/libs/vuex/3.1.0/vuex.min.js',
                    type: 'js'
                  },
                  {
                    path: '//cdnjs.cloudflare.com/ajax/libs/vue-router/3.0.2/vue-router.min.js',
                    type: 'js'
                  },
                  {
                    path: '//cdnjs.cloudflare.com/ajax/libs/element-ui/2.6.1/index.js',
                    type: 'js'
                  }
                ],
                append: false,
                publicPath: ''
            }),
            new ZipPlugin({
                path: "../release",
                filename: 'hpx_admin.zip',
                fileOptions: {
                    mtime: new Date(),
                    mode: 0o100664,
                    compress: true,
                    forceZip64Format: false,
                }
            })
            // 预渲染插件
            // new PrerenderSPAPlugin({
            //     // Required - The path to the webpack-outputted app to prerender.
            //     staticDir: path.join(__dirname, '../dist'),
            //     // Required - Routes to render.
            //     routes: [ '/'],                
            //     // staticDir: path.join(__dirname, '../dist'),
            //     // outputDir: path.join(__dirname, '../prerendered'),
            //     // indexPath: path.join(__dirname, '../dist', 'index.html'),
            //     // routes: ['/index.html'],
            //     // minify: {
            //     //     collapseBooleanAttributes: true,
            //     //     collapseWhitespace: true,
            //     //     decodeEntities: true,
            //     //     keepClosingSlash: true,
            //     //     sortAttributes: true
            //     // },

            //     renderer: new Renderer({
            //         renderAfterDocumentEvent: 'render-event'
            //     }),
            //     // server: {
            //     //     port: 3000
            //     // }            
            // })
        ]

    });
}